001    /*
002     * Copyright 2004 Stephen J. McConnell.
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.metro.info;
020    
021    import java.util.Properties;
022    
023    /**
024     * A category descriptor describes a logging channel that 
025     * a component type uses.
026     *
027     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
028     * @version 1.0.1
029     */
030    public class CategoryDescriptor
031        extends Descriptor
032    {
033       /**
034        * Serial version identifier.
035        */
036        static final long serialVersionUID = 1L;
037    
038       /**
039        * Constant category separator.
040        */
041        public static final String SEPERATOR = ".";
042    
043       /**
044        * Default priority value.
045        */
046        public static final Priority PRIORITY = Priority.DEBUG;
047    
048    
049        private final String m_name;
050        
051        private final Priority m_priority;
052    
053        /**
054         * Create a descriptor for logging category.
055         *
056         * @param name the logging category name
057         * @param priority the default priority value
058         * @param attributes a set of attributes associated with the declaration
059         *
060         * @exception NullPointerException if name argument is null
061         */
062        public CategoryDescriptor( final String name, final Priority priority, final Properties attributes )
063            throws NullPointerException
064        {
065            super( attributes );
066            if( null == name )
067            {
068                throw new NullPointerException( "name" );
069            }
070            m_name = name;
071            if( null == priority )
072            {
073                m_priority = PRIORITY;
074            }
075            else
076            {
077                m_priority = priority;
078            }
079        }
080    
081        /**
082         * Return the name of logging category.
083         *
084         * @return the category name.
085         */
086        public String getName()
087        {
088            return m_name;
089        }
090    
091        /**
092         * Return the default logging priority.
093         *
094         * @return the default priority.
095         */
096        public Priority getDefaultPriority()
097        {
098            return m_priority;
099        }
100    
101       /**
102        * Test is the supplied object is equal to this object.
103        * @param other the other object
104        * @return true if the object are equivalent
105        */
106        public boolean equals( Object other )
107        {
108            if( super.equals( other ) && ( other instanceof CategoryDescriptor ) )
109            {
110                CategoryDescriptor descriptor = (CategoryDescriptor) other;
111                if( !equals( m_name, descriptor.m_name ) )
112                {
113                    return false;
114                }
115                else
116                {
117                    return equals( m_priority, descriptor.m_priority );
118                }
119            }
120            else
121            {
122                return false;
123            }
124        }
125    
126       /**
127        * Return the hashcode for the object.
128        * @return the hashcode value
129        */
130        public int hashCode()
131        {
132            int hash = super.hashCode();
133            hash ^= m_name.hashCode();
134            hash ^= m_priority.hashCode();
135            return hash;
136        }
137    }